package com.mofang.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mofang.R;

public class YearLengthSelectAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private List<LoanTime> data;
	Context context;

	public YearLengthSelectAdapter(Context context, List<LoanTime> data) {
		this.mInflater = LayoutInflater.from(context);
		this.context = context;
		setData(data);
	}

	
	
	public void setData(List<LoanTime> data) {
		this.data = data;
	}



	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder myHolder;
		if (convertView == null) {
			myHolder = new Holder();
			convertView = mInflater.inflate(R.layout.common_select_list_item,
					null);
			myHolder.name = (TextView) convertView
					.findViewById(R.id.txt_text);
			convertView.setTag(myHolder);
		} else {
			myHolder = (Holder) convertView.getTag();
		}
		myHolder.name.setText(data.get(position).getLongtime());
		return convertView;
	}

	class Holder {
		TextView name;
	}

	public static class LoanTime{
		private int year;
		private String longtime;
		private float profit;
		public float getProfit() {
			return profit;
		}
		public LoanTime(int year) {
			this.year=year;
			this.longtime =year+"年（"+12*year+"）期";
			if (year<=5) {
				this.profit=(float) 6.88;
			}
			else if(year>5&&year<=10){
				this.profit=(float) 6.72;
			}else if (year>10&&year<20) {
				this.profit=(float) 6.31;
			}else if (year>20&&year<=30) {
				this.profit=(float) 6.10;
			}
		}
		public int getYear() {
			return year;
		}
		public void setYear(int year) {
			this.year = year;
		}
		public String getLongtime() {
			return longtime;
		}
		
	}
}
